<template>
  <div class="wrap">
    <h1>TodoList</h1>
    <div class="header">
      <TodoInput></TodoInput>
    </div>
    <div class="content">
      <div class="unCompleted" v-if="todoStore.unCompletedTodos.length > 0">
        <h2>待完成</h2>
        <TodoItem v-for="(item, index) in todoStore.unCompletedTodos" :key="item.id" :item="item" :index="index">
        </TodoItem>
      </div>
      <div v-else>
        <h2>待完成</h2>
        <p>暂无任务</p>
      </div>
      <div class="Completed" v-if="todoStore.CompletedTodos.length > 0">
        <h2>已完成</h2>
        <TodoItem v-for="(item, index) in todoStore.CompletedTodos" :key="item.id" :item="item" :index="index">
        </TodoItem>
      </div>

    </div>
  </div>
</template>

<script setup>
import TodoItem from './TodoItem.vue'
import TodoInput from './TodoInput.vue'
import { useTodoStore } from '../store/todoStore.js'; // 引入store
const todoStore = useTodoStore(); // 实例化store
console.log(todoStore.todos)
</script>

<style scoped>
h1,
h2,
p {
  color: #333
}

.wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 600px;
  padding: 16px;
  border: 1px solid #ccc;
  border-radius: 16px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.header {
  width: 80%;
  margin-bottom: 10px;
}

.content {
  width: 80%;
  padding: 10px;
}

.Completed {
  opacity: .6;
}
</style>